package com.sghd.candy.module.element.manager;

import com.sghd.common.ramcache.anno.Inject;
import com.sghd.common.ramcache.service.EntityCacheService;
import com.sghd.pojo.fight.game.ChessType;
import org.springframework.stereotype.Component;

/**
 * @author Allen
 * @date 2018/12/21
 */
@Component
public class PlayerElementManager {
    @Inject
    private EntityCacheService<Long, PlayerElement> playerElementCache;

    public PlayerElement getPlayerElement(long playerId) {
        return playerElementCache.loadOrCreate(playerId, builder -> PlayerElement.valueOf(playerId));
    }

    public void change(PlayerElement playerElement, int changeNum) {
        playerElement.change(changeNum);
    }

    public void upgrade(PlayerElement playerElement, ChessType chessType) {
        playerElement.upgrade(chessType);
    }
}
